//
//  ZLExamBeginViewController.m
//  ZLExamination
//
//  Created by Zheng on 2017/8/18.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExamBeginViewController.h"
#import "ZLExamBeiginSheetViewController.h"
#import "ZLBaseNavigationController.h"

#import "ZLExamBeginHeaderView.h"
#import "ZLExamBeginFooterView.h"
#import "ZLExamBeginCell.h"
#import "ZLExamBeginExitPromptView.h"
#import "ZLExamBeginSheetCommitView.h"

#import "ZLExamBeginModel.h"

@interface ZLExamBeginViewController () <UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) ZLExamBeginHeaderView *headerView;
@property (nonatomic, strong) ZLExamBeginFooterView *footerView;
@property (nonatomic, strong) UICollectionView *bgCollectionView;
@property (nonatomic, strong) ZLExamBeginExitPromptView *promptView; //退出提示
@property (nonatomic, strong) ZLExamBeginSheetCommitView *commitView; //交卷提示
/** 暂停提示*/
@property (nonatomic,strong) ZLExamBeginExitPromptView* pauseView;
@property (nonatomic, strong) UILabel *timeLbl; //时间显示

@property (nonatomic) dispatch_source_t timer; //计时线程
@property (nonatomic) NSInteger currentTime; //剩余秒数

@property (nonatomic) NSUInteger pageNumber; //当前页数
@property (nonatomic) NSUInteger totalPageNumber; //总页数

@property (nonatomic, copy) NSArray<NSMutableArray *> *totalQuestions; //单选多选 总
@property (nonatomic, strong) NSMutableArray<ZLExamBeginListModel *> *multiples;
@property (nonatomic, strong) NSMutableArray<ZLExamBeginListModel *> *singles; //答案集合
@property (nonatomic, copy) NSArray<NSString *> *questionTitles; //单选项


/** 练习题外部 大model*/
@property (nonatomic,strong) ZLExamBeginModel* examModel;
/** 练习题每道题 小model*/
@property (nonatomic,strong) ZLExamBeginListModel* examListModel;
/** 所有题的考试答案数组*/
@property (nonatomic,strong) NSMutableArray* allAnswerArray;
/** 开始考试/继续考试 接口*/
@property (nonatomic, copy) NSString *api;
/** 无数据退出提示*/
@property (nonatomic,strong) ZLExamBeginExitPromptView* noDataExitView;
@end

@implementation ZLExamBeginViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.timeLbl.hidden = NO;
}

- (void)setActionStyle:(ActionStyle)actionStyle
{
    _actionStyle = actionStyle;
}
#pragma mark - 点击事件
- (void)myClickAction {
    __weak typeof(self) weakSelf = self;
    
#pragma mark 上翻页操作
    [_footerView setLeftClick:^{
        kCX_LOG(@"向上");
        if (_pageNumber > 1) {
            weakSelf.pageNumber--;
            [weakSelf setDisplayPageNumber];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_pageNumber-1 inSection:0];
            [weakSelf.bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
        }
    }];
    
#pragma mark 下翻页操作
    [_footerView setRightClick:^{
        kCX_LOG(@"向下");
        
        if (_pageNumber == _totalPageNumber) {
            ZLExamBeiginSheetViewController *ebsVC = [[ZLExamBeiginSheetViewController alloc] init];
            ebsVC.examModel = weakSelf.examModel;
            ebsVC.questions = weakSelf.totalQuestions;
            ebsVC.curriculum_id = weakSelf.curriculum_id;
            
            ZLBaseNavigationController *nav = [[ZLBaseNavigationController alloc] initWithRootViewController:ebsVC];
            [weakSelf presentViewController:nav animated:YES completion:^{
                
            }];
            return;
        }
        
        if (_pageNumber < _totalPageNumber) {
            weakSelf.pageNumber++;
            [weakSelf setDisplayPageNumber];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_pageNumber-1 inSection:0];
            [weakSelf.bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
        }
        
    }];
#pragma mark 答题卡操作
    [_footerView setSheetClick:^{
        kCX_LOG(@"答题卡");
        
        ZLExamBeiginSheetViewController *ebsVC = [[ZLExamBeiginSheetViewController alloc] init];
        ebsVC.examModel = weakSelf.examModel;
        ebsVC.questions = weakSelf.totalQuestions;
        ebsVC.curriculum_id = weakSelf.curriculum_id;
        
        ebsVC.clickCallBack = ^(NSInteger number) {
#pragma mark 答题卡选择题号
            [weakSelf scroolToDesignationRowWith:number];
        };
        weakSelf.timeLbl.hidden = YES;

        [weakSelf.navigationController pushViewController:ebsVC animated:YES];
    }];
    
#pragma mark 确定退出考试
    [_promptView setEnterCallBack:^{
         dispatch_source_cancel(weakSelf.timer);
         weakSelf.timeLbl.hidden = YES;
         [weakSelf.timeLbl removeFromSuperview];
         _timeLbl = nil;
        
        //退出提交白卷
        if (!weakSelf.examModel.user_paper_id) {
            return ;
        }
        
        NSDictionary *param = @{@"user_paper_id":weakSelf.examModel.user_paper_id};
        
        YCRequestDataService *manager = [YCRequestDataService sharedManager];
        [manager Post:@"paper/paper/sub_paper" parameters:param success:^(id response) {
            if (response[@"error_code"]) {
                NSLog(@"%@",response[@"error_msg"]);
                [manager showHUDSleepText:weakSelf withTitle:response[@"error_msg"]];
            } else {
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"user_paper_id"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [weakSelf dismissViewControllerAnimated:YES completion:nil];
            }
        } failure:^{
            NSLog(@"网络或服务器出错");
        }];
    }];
    
#pragma mark 继续考试
    [_pauseView setEnterCallBack:^{
        //继续考试网络请求
        
        weakSelf.view.userInteractionEnabled = YES;
        [weakSelf examTimeCalculationWithSeconds:weakSelf.currentTime];
        
        _api = @"paper/paper/continue_paper";
        NSDictionary *param = @{@"user_paper_id":weakSelf.user_paper_id};

        YCRequestDataService *manager = [YCRequestDataService sharedManager];
        [manager Post:weakSelf.api parameters:param success:^(id response) {

        } failure:^{
            NSLog(@"网络或服务器出错");
        }];
    }];
    
#pragma mark 自动交卷
    [_commitView setEnterCallBack:^{
        kCX_LOG(@"自动交卷");
    }];
    
    //数据有问题, 弹窗点击退出
    [_noDataExitView setEnterCallBack:^{
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
}


- (void)scroolToDesignationRowWith:(NSInteger)rowNumber {
#pragma mark 跳转到固定题号的位置
    _pageNumber = rowNumber+1;
    [self setDisplayPageNumber];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowNumber inSection:0];
    [_bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
};

- (void)backBarButtonPressed:(id)sender {
#pragma mark 退出考试
    kCX_LOG(@"是否退出");
    [_promptView showExitPromptView];
}

- (void)answerWithQuestionNumber:(NSInteger)item withAnswerNumber:(NSInteger)answer {
#pragma mark 答题操作
    kCX_LOG(@"第%ld题, 选项%ld",item,answer);
    
    if (item < _singles.count) {
        [_singles enumerateObjectsUsingBlock:^(ZLExamBeginListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (item == obj.questionNumber.integerValue) {
                if (![obj.questionAnswer isEqualToString:_questionTitles[answer]]) {
                    obj.questionAnswer = _questionTitles[answer];
                    obj.isAnswer = YES;
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:item inSection:0];
                    [_bgCollectionView reloadItemsAtIndexPaths:@[indexPath]];
                }
            }
        }];
    } else {
        [_multiples enumerateObjectsUsingBlock:^(ZLExamBeginListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (item == obj.questionNumber.integerValue) {
                if (obj.answers.count == 0) {
                    obj.answers = [NSMutableArray array];
                    [obj.answers addObject:_questionTitles[answer]];
                } else {
                    if ([obj.answers containsObject:_questionTitles[answer]]) {
                        [obj.answers removeObject:_questionTitles[answer]];
                    } else {
                        [obj.answers addObject:_questionTitles[answer]];
                    }
                }
                
                if (obj.answers.count > 0) {
                    obj.isAnswer = YES;
                } else {
                    obj.isAnswer = NO;
                }
                
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:item inSection:0];
                [_bgCollectionView reloadItemsAtIndexPaths:@[indexPath]];
            }            
        }];
    }
}

- (void)rightBarButtonPressed:(id)sender {
#pragma mark 暂停操作
    kCX_LOG(@"暂停");
    if (_currentTime != 0) {
        dispatch_source_cancel(_timer);
        self.view.userInteractionEnabled = NO;
        
        //先计算成绩, 再网络请求暂停
//        [self paperScore];
        
//        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"pause"];
//        [[NSUserDefaults standardUserDefaults] synchronize];
        
        [_pauseView showExitPromptView];
    }

}

//计算试卷成绩
- (void)paperScore
{
    _allAnswerArray = [NSMutableArray array];
    NSMutableArray<ZLExamBeginListModel *> *singleArr = _totalQuestions[0];
    NSMutableArray<ZLExamBeginListModel *> *multipleArr = _totalQuestions[1];
    //打印单选选择的内容
    [singleArr enumerateObjectsUsingBlock:^(ZLExamBeginListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.questionAnswer) {
            NSString *answerStr = [NSString stringWithFormat:@"%@:%@", obj.n_id, obj.questionAnswer];
            NSLog(@"%@", answerStr);
            [_allAnswerArray addObject:answerStr];
        } else {
            NSString *answerStr = [NSString stringWithFormat:@"%@: ", obj.n_id];
            NSLog(@"%@", answerStr);
            [_allAnswerArray addObject:answerStr];
        }
    }];

    //打印多选选择的内容
    [multipleArr enumerateObjectsUsingBlock:^(ZLExamBeginListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.answers.count != 0) {
            
            //obj.answers数组里面按照abcd 排序 后放到resultArray数组里
            NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch|NSNumericSearch|
            NSWidthInsensitiveSearch|NSForcedOrderingSearch;
            
            NSComparator sort = ^(NSString *obj1,NSString *obj2){
                
                NSRange range = NSMakeRange(0,obj1.length);
                
                return [obj1 compare:obj2 options:comparisonOptions range:range];
            };
            NSArray *resultArray = [obj.answers sortedArrayUsingComparator:sort];
            //                obj.answers
            NSString *tempStr = [resultArray componentsJoinedByString:@""];
            NSString *answerStr = [NSString stringWithFormat:@"%@:%@", obj.n_id, tempStr];
            NSLog(@"%@", answerStr);
            [_allAnswerArray addObject:answerStr];
            
        } else {
            NSString *answerStr = [NSString stringWithFormat:@"%@: ", obj.n_id];
            NSLog(@"%@", answerStr);
            [_allAnswerArray addObject:answerStr];
        }
    }];
  
    NSString *scoreStr = [_allAnswerArray componentsJoinedByString:@"|"];
    NSLog(@"!!!%@", scoreStr);
    //提交考试信息
    [self pauseExamLoadDataWith:scoreStr];
}


#pragma mark - 暂停网络请求
- (void)pauseExamLoadDataWith: (NSString *)scoreStr
{
    //暂停数据请求
    NSDictionary *param = @{@"user_paper_id":_examModel.user_paper_id,
                            @"score" : scoreStr,
                            @"suspend_subject_id" : _examListModel.n_id
                            };
    NSLog(@"%@", param);
    YCRequestDataService *manager = [YCRequestDataService sharedManager];
    [manager Post:@"paper/paper/suspend_paper" parameters:param success:^(id response) {

    } failure:^{
        NSLog(@"网络或服务器出错");
    }];

}
#pragma mark 自动交卷
- (void)timeOverToAutoCommitExam {
    [_commitView showCommitViewAutoCommit];
}

#pragma mark - scrollview delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSInteger index = (NSInteger)scrollView.contentOffset.x/(NSInteger)kSCREEN_WIDTH + 1;
    if (_pageNumber != index) {
        _pageNumber = index;
        [self setDisplayPageNumber];
    }
}

#pragma mark - 设置显示页数
- (void)setDisplayPageNumber {
    _headerView.titleLbl.text = _pageNumber>_singles.count? @"多项选择题":@"单项选择题";
    NSString *selectedNumber = [NSString stringWithFormat:@"%lu",_pageNumber];
    NSString *totalNumber = [NSString stringWithFormat:@"%lu",_totalPageNumber];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@/%@",selectedNumber,totalNumber]];
    NSRange range = NSMakeRange([selectedNumber length], [totalNumber length]+1);
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:range];
    _headerView.numberLbl.attributedText = str;
}

#pragma mark - 视图生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    _questionTitles = @[@"A",@"B",@"C",@"D"];
    _pageNumber = 1;
    //添加子视图
    [self subviewsInView];
    [self listLoadData];
    [self myClickAction];
}

#pragma mark - 加载考试数据
- (void)listLoadData
{
    _singles = [NSMutableArray array];
    _multiples = [NSMutableArray array];
        
    NSDictionary *param;
    
    _api = @"paper/paper/create_paper";
    param = @{@"curriculum_id":_curriculum_id};


//    if (self.actionStyle == ActionStyleBegin) {
//        _api = @"paper/paper/create_paper";
//        param = @{@"curriculum_id":_curriculum_id};
//    } else {
//        _api = @"paper/paper/continue_paper";
//        param = @{@"user_paper_id":_user_paper_id};
//    }
    
    YCRequestDataService *manager = [YCRequestDataService sharedManager];
    [manager Post:_api parameters:param success:^(id response) {
        if (response[@"error_code"]) {
            _noDataExitView.titleLbl.text = response[@"error_msg"];
            [_noDataExitView showExitPromptView];
            
        } else {
            
            _examModel = [[ZLExamBeginModel alloc] initWithDataDic:response[@"response_data"][@"lists"]];
            
//            _user_paper_id = _examModel.user_paper_id;
            
            [[NSUserDefaults standardUserDefaults] setObject:_examModel.user_paper_id forKey:@"user_paper_id"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            _totalPageNumber = [_examModel.subject_num integerValue];
            self.headerView.examNameLbl.text = _examModel.title;
            NSArray<NSDictionary *> *lists = _examModel.subject_lists;
            [lists enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                ZLExamBeginListModel *examListModel = [[ZLExamBeginListModel alloc] initWithDataDic:obj];
                //单选或者多选
                if ([examListModel.type integerValue] == 1) {
                    examListModel.questionNumber = @(idx);
                    examListModel.isSingles = YES;
                    if (_actionStyle == ActionStyleContinue) {
                        //TODO:(单选)继续考试给每个选项传值
                        examListModel.questionAnswer = examListModel.the_answer;
                    }

                    [_singles addObject:examListModel];
                    
                } else if ([examListModel.type integerValue] == 2) {
                    examListModel.questionNumber = @(idx);
                    examListModel.isSingles = NO;
                    //TODO:(多选)继续考试给每个选项传值 ?
                    
                    [_multiples addObject:examListModel];
                }
            }];
            NSLog(@"%ld  %ld", _singles.count, _multiples.count);
            if (_singles.count != 0 || _multiples.count != 0) {
                _totalQuestions = @[_singles,_multiples];
                                //设置显示页数
                [self setDisplayPageNumber];
                //用户点击事件
              
                //计时开始
                [self examTimeCalculationWithSeconds:[_examModel.examination_time integerValue] * 60];
                [_bgCollectionView reloadData];
            } else {
                [manager showHUDSleepText:self withTitle:@"暂无数据"];
            }
        }
        
    } failure:^{
        NSLog(@"网络或服务器出错");
    }];

}

#pragma mark - 考试时间计算
- (void)examTimeCalculationWithSeconds:(NSInteger)seconds {
    
    _timeLbl.text = [self getExamTimeWithSeconds:seconds];
    
    __block NSInteger timeout = seconds;
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0), 1.0*NSEC_PER_SEC, 0);
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout <= 0){
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                [self timeOverToAutoCommitExam];
            });
            
        } else {
            timeout--;
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            _timeLbl.text = [self getExamTimeWithSeconds:timeout];
        });
        
        _currentTime = timeout;
    });
    dispatch_resume(_timer);
}

- (NSString *)getExamTimeWithSeconds:(NSInteger)seconds {
    NSInteger hour = seconds/3600;
    NSInteger minute = seconds%3600/60;
    NSInteger second = seconds%3600%60;
    NSString *hourStr = [NSString stringWithFormat:@"0%ld",hour];
    NSString *minuteStr = minute < 10 ? [NSString stringWithFormat:@"0%ld",minute]:[NSString stringWithFormat:@"%ld",minute];
    NSString *secondStr = second < 10 ? [NSString stringWithFormat:@"0%ld",second]:[NSString stringWithFormat:@"%ld",second];
    NSString *timeStr = [NSString stringWithFormat:@"%@:%@:%@",hourStr,minuteStr,secondStr];
    return timeStr;
}


#pragma mark - 子视图
- (void)subviewsInView {
    
    [self.navigationController.view addSubview:self.timeLbl];
    
    [self showBackButtonWithImage:@"exam_back"];

    //导航栏
    [self showRightBarButtonItemWithTitle:@"暂停"];
    
    [[UIApplication sharedApplication].keyWindow addSubview:self.promptView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.commitView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.pauseView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.noDataExitView];;

    //顶部视图
    [self.view addSubview:self.headerView];
    
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(35);
    }];
    
    //底部视图
    [self.view addSubview:self.footerView];
    
    [_footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.mas_equalTo(75);
    }];
    
    //答题视图
    [self.view addSubview:self.bgCollectionView];
    
    [_bgCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(_headerView.mas_bottom);
        make.bottom.equalTo(_footerView.mas_top);
    }];
}

#pragma mark - lazy load
- (ZLExamBeginSheetCommitView *)commitView {
    if (!_commitView) {
        _commitView = [[ZLExamBeginSheetCommitView alloc] initWithFrame:(CGRect){0, 0, kSCREEN_WIDTH, kSCREENH_HEIGHT}];
    }
    return _commitView;
}

- (UILabel *)timeLbl {
    if (!_timeLbl) {
        _timeLbl = [[UILabel alloc] initWithFrame:CGRectMake(50, 20, 150, 44)];
        _timeLbl.textColor = [UIColor whiteColor];
    }
    return _timeLbl;
}

- (ZLExamBeginExitPromptView *)promptView {
    if (!_promptView) {
        _promptView = [[ZLExamBeginExitPromptView alloc] initWithFrame:kSCREEN_BOUNDS];
    }
    return _promptView;
}
- (ZLExamBeginExitPromptView *)pauseView
{
    if (!_pauseView) {
         _pauseView = [[ZLExamBeginExitPromptView alloc] initWithFrame:kSCREEN_BOUNDS];
        _pauseView.titleLbl.text = @"继续考试";
        _pauseView.contentLbl.text = @"点击按钮后，将继续考试";
        _pauseView.cancelBtn.hidden = YES;
        _pauseView.line1.hidden = YES;
        [_pauseView.enterBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(_pauseView.whiteBgView);
            make.height.mas_equalTo(kCX_Scale(55));
        }];
    }
    return _pauseView;
}

- (ZLExamBeginHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[ZLExamBeginHeaderView alloc] init];
    }
    return _headerView;
}

- (ZLExamBeginFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[ZLExamBeginFooterView alloc] init];
    }
    return _footerView;
}

- (UICollectionView *)bgCollectionView {
    if (!_bgCollectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(kSCREEN_WIDTH, kSCREENH_HEIGHT-110-64);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        _bgCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _bgCollectionView.delegate = self;
        _bgCollectionView.dataSource = self;
        _bgCollectionView.pagingEnabled = YES;
        _bgCollectionView.bounces = NO;
        _bgCollectionView.showsVerticalScrollIndicator = NO;
        _bgCollectionView.showsHorizontalScrollIndicator = NO;
        _bgCollectionView.backgroundColor = [UIColor whiteColor];
        [_bgCollectionView registerClass:[ZLExamBeginCell class] forCellWithReuseIdentifier:kZLExamBeginCell_ID];
        [_bgCollectionView registerClass:[ZLExamBeginCell class] forCellWithReuseIdentifier:kZLExamBeginMultipleCell_ID];
    }
    return _bgCollectionView;
}

#pragma mark - collectionview datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _totalPageNumber;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    __weak typeof(self) weakSelf = self;
    
    NSLog(@"%ld", _singles.count);
    if (indexPath.item < _singles.count) {
        //单选
        ZLExamBeginCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kZLExamBeginCell_ID forIndexPath:indexPath];
        cell.itemNumber = indexPath.item;
        cell.answerCallBack = ^(NSInteger item, NSInteger answer) {
            [weakSelf answerWithQuestionNumber:item withAnswerNumber:answer];
        };
        _examListModel = _singles[indexPath.item];
        cell.model = _examListModel;
        [cell.myTableView reloadData];
        return cell;

    } else {
        //多选
        ZLExamBeginCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kZLExamBeginMultipleCell_ID forIndexPath:indexPath];
        cell.itemNumber = indexPath.item;
        cell.answerCallBack = ^(NSInteger item, NSInteger answer) {
            [weakSelf answerWithQuestionNumber:item withAnswerNumber:answer];
        };
        _examListModel = _multiples[indexPath.item-_singles.count];
        cell.model = _examListModel;
        [cell.myTableView reloadData];
        return cell;
    }
    
}
- (ZLExamBeginExitPromptView *)noDataExitView
{
    if (!_noDataExitView) {
        _noDataExitView = [[ZLExamBeginExitPromptView alloc] initWithFrame:kSCREEN_BOUNDS];
        _noDataExitView.contentLbl.text = @"退出考试";
        _noDataExitView.cancelBtn.hidden = YES;
        _noDataExitView.line1.hidden = YES;
        [_noDataExitView.enterBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(_noDataExitView.whiteBgView);
            make.height.mas_equalTo(kCX_Scale(55));
        }];
    }
    return _noDataExitView;
}
#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
